package com.dao;

import java.util.List;
import java.util.Map;
import hyl.core.db.MyDB;
import hyl.core.db.MySqlSelect;
import hyl.core.db.SelectWhere;

public class SqlOfChat {
	private static final String select_crowd = "select a.id,a.uid,a.gname,a.is0,a.ctime,a.remark from crowd a where 1=1 ";

	// 读取用户信息
	public static Map<String, Object> getCrowdByID(MyDB db, Integer id) {
		String sql = select_crowd + "and a.id= " + id;

		return db.queryMap(sql, null);
	}

	private static final String contact_select = "SELECT a.uid ,a.cid,a.is0,a.is1,a.is2,a.ctype,a.t0 title,b.`tl0` headimg, b.t7 sex FROM user_contacts a inner JOIN user_conf b";

	public static List<Map<String, Object>> get我的联系人(Integer uid, Integer 朋友类型) {
		// 最多保留10个备份
		String sql = contact_select + " ON a.cid=b.id WHERE 1=1";
		MySqlSelect select = MySqlSelect.getInstance(sql);
		SelectWhere sw = new SelectWhere();
		sw.add("and a.uid=? ", uid);
		sw.add("and a.ctype=?  ", 朋友类型);
		select.addParams(sw);
		return select.getList();
	}

	public static List<Map<String, Object>> get群聊对象(MyDB db, int friend) {
		// 最多保留10个备份
		String sql = contact_select + " ON a.uid=b.id WHERE a.ctype=1 and a.cid=" + friend;
		return db.queryList(sql, null);

	}

	public static Map<String, Object> get聊天对象(MyDB db, Integer userid, int friend) {
		// 最多保留10个备份
		String sql = contact_select + " and a.uid=" + userid + " and a.cid=" + friend + " and a.ctype= 0";
		return db.queryMap(sql, null);

	}
}
